package artid.com.arttogo.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.util.Map;

public class WhiteListDb extends SQLiteOpenHelper {
	public static final int VERSION = 2;
	public static final String TABLE_NAME = "qrhistory_four";// 表名
	public static final String QR_Date = "qrdate";// 扫码时间
	public static final String QR_Info = "qrinfo";// 描述信息
	public static final String QR_Url = "qrurl";// 扫码码值
	public static final String QR_ResourceId = "qrresourceId";// 资源ID
	public static final String QR_VideoId = "qrvideoId";// 视频主表ID
	public static final String QR_ResourceName = "qrresourceName";// 资源名称
	public static final String QR_SuitName = "qrsuitName";// 套册名称
	public static final String QR_SubjectName = "qrsubjectName";// 科目名称
	public static final String QR_Type = "qrtype";// 码类型

	public WhiteListDb(Context context) {
		super(context, "whitelist.db", null, VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub

		String qrSql = "create table if not exists qrhistory_four("
				+ "_id Integer not null primary key autoincrement,"// ID
				+ QR_Date
				+ " varchar(50) not null,"// 扫码时间
				+ QR_Info
				+ " varchar(200) not null,"// 扫码描述
				+ QR_VideoId
				+ " varchar(50),"// 视频所用
				+ QR_Url + " varchar(80) not null," + QR_ResourceId
				+ "  varchar(50) not null," + QR_ResourceName
				+ "  varchar(50), " + QR_SuitName + " varchar(50),"
				+ QR_SubjectName + " varchar(50)," + QR_Type + " varchar(50)"
				+ ")";

		db.execSQL(qrSql);

	}

	public long insert(Map<String, String> map) {
		SQLiteDatabase db = this.getWritableDatabase();
		ContentValues cv = new ContentValues();
		cv.put(QR_Date, map.get(QR_Date));
		System.out.println("map.get(QR_Date)=" + map.get(QR_Date));
		cv.put(QR_Url, map.get(QR_Url));
		cv.put(QR_ResourceId, map.get(QR_ResourceId));
		cv.put(QR_ResourceName, map.get(QR_ResourceName));
		cv.put(QR_SuitName, map.get(QR_SuitName));
		cv.put(QR_SubjectName, map.get(QR_SubjectName));
		cv.put(QR_Type, map.get(QR_Type));
		cv.put(QR_Info, map.get(QR_Info));
		if (map.get(QR_Type).contains("视频码"))
			cv.put(QR_VideoId, map.get(QR_VideoId));
		long row = db.insert(TABLE_NAME, null, cv);
		return row;
	}

	@Override
	public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub

	}

}
